<template>
    <div>
        <el-table
        ref="multipletable"
        tooltip-effect="dark"
        @selection-change="handleselectionchange"
      :data="tableData"
      border
      style="">
        <el-table-column
       type="selection"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="name"
        label="小区名称"
        width="165"
        align="center">
      </el-table-column>
      <el-table-column
        prop="address"
        label="小区地址"
        width="200"
        align="center">
      </el-table-column>
    </el-table>
        <el-button type="primary" @click="confirmcommunities()">确 定</el-button>
     <el-button type="warning" @click="cancel()">取消</el-button>
    </div>
</template>
<script>
export default {
    data() {
      return{
           tableData:[], 
        //   current:{},
        // 多选数据
             multipleselection:[],
            //返回数组
            multiplearr:[]
          
      }
    },
     mounted(){
      this.$axios.get("http://localhost:8080/merchant/findallcommunities").then(res =>{
         console.log(res.data)//ResponseResult
        console.log(res.data.data)  
        this.tableData = res.data.data
        
      })
    },
    methods:{
              //得到选中数据
      handleselectionchange:function(val){
        this.multipleselection=val
      },
         //批量
      confirmcommunities:function(){
      
        // 要从子组件重新赋值
        this.multiplearr.length=0
        let val=this.multipleselection
         if(val){
            for(var i=0;i<val.length;i++){
                
                this.multiplearr.push(val[i])
            }
        }
                     //   清除选中状态
        this.$refs.multipletable.clearSelection()
        this.$emit("confirmcommunities",this.multiplearr)



      },
       cancel:function(){
         this.$emit("cancel",false)
        },
    }
}
</script>
<style>
</style>